import { createRouter, createWebHashHistory } from 'vue-router'
import NProgress from 'nprogress'

const routes = [
  {
    path: '/',
    name: '主页',
    component: () => import('@/views/home/index.vue'),
    redirect: '/welcome',
    children: [
      {
        path: '/welcome',
        name: '欢迎',
        component: () => import('@/views/welcome/index.vue'),
      },
      {
        path: '/userManage',
        name: '用户管理',
        component: () => import('@/views/userManage/index.vue'),
      },
    ],
  },
]

const router = createRouter({
  history: createWebHashHistory(),
  routes,
})

router.beforeEach((to, from, next) => {
  NProgress.start()
  // let token = window.localStorage.getItem('USER_TOKEN_INRE')
  // if (!token && !wtiterPath.includes(to.path)) {
  //   next({ path: '/' })
  //   return
  // }

  next()
})

router.afterEach(() => {
  NProgress.done()
})

export default router
